package org.yzh.web.waterMeter.dto.basics;

import org.yzh.framework.annotation.Property;
import org.yzh.framework.enums.DataType;
import org.yzh.framework.message.AbstractBody;
import org.yzh.framework.message.AbstractMessage;

import java.util.Date;

public class WaterMeterMessage<T extends AbstractBody> extends AbstractMessage<T> {

    protected Integer noUseInfo1 = 0x68;//报文头无用数据
    protected Integer headerLength = 18;
    protected Integer bodyLength = 0;
    protected byte[] noUseInfo2 = {0x00,0x00,0x68};//报文头无用数据
    protected Integer control;//控制域
    protected String hubId;//集线器编号
    protected Integer noUseInfo3=0x04;//无用域1
    protected Integer functionClass;//功能类
    protected Integer seq=0x71;//序列号，区分多个消息同时发送，分桢，第一位是0x7n,用于计数
    protected Integer terminalNum = 0x0000;//表序号
    protected Integer type;

    public WaterMeterMessage() {
    }

    public WaterMeterMessage(WaterMeterMessage waterMeterMessage, Integer functionClass,Integer control, Integer type) {
        this.type = type;
        this.hubId = waterMeterMessage.hubId;
        this.noUseInfo1 = waterMeterMessage.noUseInfo1;
        this.noUseInfo2 = waterMeterMessage.noUseInfo2;
        this.hubId = waterMeterMessage.hubId;
        this.noUseInfo3 = waterMeterMessage.noUseInfo3;
        this.functionClass =functionClass;
        this.control = control;
        this.seq = waterMeterMessage.seq;
    }

    public WaterMeterMessage(Integer type, String hubId, T body) {
        this.type = type;
        this.hubId = hubId;
        this.body = body;
    }

    public WaterMeterMessage(Integer functionClass,Integer control, Integer type, String hubId) {
        this.type = type;
        this.hubId = hubId;
        this.functionClass = functionClass;
        this.control = control;
    }

    public WaterMeterMessage(Integer type, String hubId) {
        this.type = type;
        this.hubId = hubId;
    }

    @Property(index = 0, type = DataType.BYTE, desc = "无用域")
    public Integer getNoUseInfo1() {
        return noUseInfo1;
    }

    public void setNoUseInfo1(Integer noUseInfo1) {
        this.noUseInfo1 = noUseInfo1;
    }

    @Property(index = 1, type = DataType.WORD, desc = "报文长度")
    @Override
    public Integer getBodyLength() {
        return bodyLength;
    }

    public void setBodyLength(Integer bodyLength) {
        this.bodyLength = bodyLength ; //结尾长度
    }

    @Property(index = 2, type = DataType.BYTES, length = 3, desc = "无用域")
    public byte[] getNoUseInfo2() {
        return noUseInfo2;
    }

    public void setNoUseInfo2(byte[] noUseInfo2) {
        this.noUseInfo2 = noUseInfo2;
    }

    @Property(index = 3, type = DataType.BYTE, desc = "控制域")
    public Integer getControl() {
        return control;
    }

    public void setControl(Integer control) {
        this.control = control;
    }

    @Property(index = 4, type = DataType.BCD8421, length = 4, desc = "集线器ID")
    public String getHubId() {
        return hubId;
    }

    public void setHubId(String hubId) {
        this.hubId = hubId;
    }

    @Property(index = 5, type = DataType.BYTE, desc = "无用域")
    public Integer getNoUseInfo3() {
        return noUseInfo3;
    }

    public void setNoUseInfo3(Integer noUseInfo3) {
        this.noUseInfo3 = noUseInfo3;
    }

    @Property(index = 6, type = DataType.BYTE,length = 1, desc = "功能大类")
    public Integer getFunctionClass() {
        return functionClass;
    }

    public void setFunctionClass(Integer functionClass) {
        this.functionClass = functionClass;
    }

    @Property(index = 7, type = DataType.BYTE, desc = "序列号")
    public Integer getSeq() {
        return seq;
    }

    public void setSeq(Integer seq) {
        this.seq = seq;
    }

    @Property(index = 7, type = DataType.WORD, desc = "表序号")
    public Integer getTerminalNum() {
        return terminalNum;
    }

    public void setTerminalNum(Integer terminalNum) {
        this.terminalNum = terminalNum;
    }

    @Property(index = 8 , type = DataType.WORD, desc = "功能小类")
    public Integer getType() {
        return this.type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Override
    public Integer getHeaderLength() {
        return headerLength;
    }

    public void setHeaderLength(Integer headerLength) {
        this.headerLength = headerLength;
    }

    @Override
    public boolean hasSubPackage() {
        return false;
    }

    public static void main(String[] args) {
        System.out.println(Integer.parseInt("184d0a",16));
    }

}